<?php
/**
 * Created by PhpStorm.
 * User: liuhaonan
 * Date: 2020/2/7
 * Time: 11:58 AM
 */

namespace app\sonpartner\controller;

use redis\RedisPackage;
use sms\Sms;

class SendSms
{
    /**
     * 发送短信
     * @param $tel
     * @param $code
     * @return bool
     */
    function send_sms()
    {
        RedisPackage::getInstance();
        $input = input();
        $tel = isset($input['tel']) ? $input['tel'] : '';
        if(empty($tel)) {
            returnError('请输入手机号');
        }
        //验证手机号
        $user = db('partner')
            ->alias('p')
            ->join('user_manage u', 'p.uid=u.id', 'LEFT')
            ->where('u.tel', $tel)
            ->find();
        if(empty($user)) {
            returnError('该合伙人手机不存在');
        }
        $code = rand(1000,9999);
        $sms = new Sms();
        $res = $sms->sendSms($tel, $code);
        RedisPackage::set('code_' . $tel, $code, 300);
        returnSuccess();
    }
}